<?php

declare(strict_types=1);

namespace app\core\DB\Test;

use Swoole\Coroutine;
use PDO;
class DBPoolContext{
    private static $pool = [];
    protected static $name='Resource.database';
   
    static function get()
    {
        $cid = Coroutine::getuid();
        if ($cid < 0) {
            return null;
        }
        if(isset(self::$pool[$cid][self::$name])){
            return self::$pool[$cid][self::$name];
        }

        return null;
    }

    static function put($item)
    {
        $cid = Coroutine::getuid();
        if ($cid > 0) {
            self::$pool[$cid][self::$name] = $item;
        }
    }

    static function delete()
    {
        $cid = Coroutine::getuid();
        if ($cid > 0) {
            
            // static::get()->release();
            unset(self::$pool[$cid]);
        }
    }
    

    
}